<template>
    <el-dialog v-model="visible" title="收银台" width="400" draggable overflow append-to-body>
        <div>
            <div class="flex items-center pb-2 mb-3 border-b-1 border-b-solid border-gray-200">
                <div class="w-5 text-end pr-2">#</div>
                <div class="w-60">号码</div>
                <div class="w-10 ml-2">和值</div>
                <div class="w-20">操作</div>
            </div>
            <div class="flex items-center mt-1" v-for="i in 10" :key="i">
                <div class="w-5 text-end pr-2">{{ i }}</div>
                <div class="w-60"><el-input size="small" clearable /></div>
                <div class="w-10 ml-2">80</div>
                <div class="w-20">
                    <el-button-group size="small">
                        <el-button type="info">添加</el-button>
                        <el-button type="danger">删除</el-button>
                    </el-button-group>
                </div>
            </div>
        </div>
        <div class="text-gray-500 mt-4 text-end">{{ stat.count }} 注 {{ stat.total }} 元</div>
        <template #footer>
            <el-button-group size="small">
                <el-button type="info" @click="onCopy()">批量编辑</el-button>
                <el-button type="info" @click="onCopy()">复制</el-button>
                <el-button type="info" @click="visible = false">关闭</el-button>
            </el-button-group>
        </template>
    </el-dialog>
</template>

<script setup>
import { ElMessageBox } from 'element-plus';
import { ref, watch } from 'vue';
import { copyText } from '@/utils/Utils';
import { useDltCartStore } from '@/model/DltCartModel';

const dltCart = useDltCartStore();
const visible = defineModel();
const content = ref('');
const stat = ref({
    count: 0,
    total: 0,
});
const data = ref([]);

watch(()=>dltCart.getCart(),newVal=>{
    
})
const onInput = () => {
    let arr = content.value.replace(/ {2,}/g, ' ').trim().split('\n').filter(v => v.trim().split(' ').length == 7);
    stat.value.count = arr.length;
    stat.value.total = stat.value.count * 2;
}
const onCopy = () => {
    let text = content.value.replace(/ {2,}/g, ' ').trim().split('\n').map(v => v.trim()).filter(v => v.split(' ').length == 7).join('\n');
    copyText(text);
    ElMessageBox.alert('复制成功');
}
</script>